package com.bsbm.mappers;

import com.bsbm.common.domain.Address;
import com.bsbm.common.domain.City;
import com.bsbm.member.bean.MemberBean;
import com.bsbm.member.domain.Member;
import com.bsbm.member.domain.MemberTypeEnum;

import java.util.Calendar;

/**
 * Created by SABIR IQBAL on 3/23/14.
 */
public class MemberMapper {

    public Member getDomainFromBean(MemberBean bean) {

        City city = new City();
        city.setPanchayatCd(bean.getPanchayatCd());
        city.setStateCd(bean.getStateCd());
        city.setBlockCd(bean.getBlockCd());
        city.setCityTown(bean.getTownCd());
        city.setCountry("India");
        city.setDistrictCd(bean.getDistrictCd());
        city.setVillage(bean.getVillage());
        Address address = new Address();
        address.setAddressLine1(bean.getAddressLine1());
        address.setAddressLine2(bean.getAddressLine2());
        address.setCity(city);
        address.setZip(bean.getPinCode());

        Member domain = new Member();
        domain.setId(bean.getId());
        domain.setAddress(address);
        domain.setCreatedBy("User");
        domain.setCreatedOn(Calendar.getInstance().getTime());
        domain.setDob(bean.getDob());
        domain.setEmailId(bean.getEmailId());
        domain.setFatherName(bean.getFatherName());
        domain.setIdCardNo(bean.getIdCardNo());
        domain.setMemberType(MemberTypeEnum.fromString(bean.getMemberTypeCd()));
        domain.setFormNo(bean.getFormNo());
        domain.setFirstName(bean.getFirstName());
        domain.setMiddleName(bean.getMiddleName());
        domain.setLastName(bean.getLastName());
        domain.setPhoneNumber(bean.getPhoneNumber());
        domain.setOccupationCd(bean.getOccupationCd());
        domain.setQualificationCd(bean.getQualificationCd());
        return domain;
    }

    public MemberBean getBeanFromDomain(Member domain) {

        MemberBean bean = new MemberBean();
        Address address = domain.getAddress();
        City city = address.getCity();
        bean.setId(domain.getId());
        bean.setAddressLine1(address.getAddressLine1());
        bean.setAddressLine2(address.getAddressLine2());
        bean.setTownCd(city.getCityTown());
       // bean.setCountry(address.getCountry());
        bean.setStateCd(city.getStateCd());
        bean.setPinCode(address.getZip());
        bean.setVillage(city.getVillage());
        bean.setPanchayatCd(city.getPanchayatCd());
        bean.setBlockCd(city.getBlockCd());
        bean.setDistrictCd(city.getDistrictCd());

        bean.setCreatedBy("User");
        bean.setCreatedOn(domain.getCreatedOn());
        bean.setDob(domain.getDob());
        bean.setEmailId(domain.getEmailId());
        bean.setFatherName(domain.getFatherName());
        bean.setIdCardNo(domain.getIdCardNo());
        bean.setMemberTypeCd(domain.getMemberType().name());
        bean.setFormNo(domain.getFormNo());
        bean.setFirstName(domain.getFirstName());
        bean.setMiddleName(domain.getMiddleName());
        bean.setLastName(domain.getLastName());
        bean.setPhoneNumber(domain.getPhoneNumber());
        bean.setOccupationCd(domain.getOccupationCd());
        bean.setQualificationCd(domain.getQualificationCd());
        return bean;
    }

}
